home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / WIN_PRO / WTEK0593.ZIP;1 / CALLBACK.ZIP / OTIMER.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-10  |  2.0 KB  |  85 lines

  1. //--------------------------------------------------------------------------
  2. //
  3. //  OTIMER.H
  4. //
  5. //  Timer class... using Object callback
  6. //
  7. //--------------------------------------------------------------------------
  8.  
  9. #include "otimer.h"
  10. #include "objcallb.h"
  11.  
  12.  
  13. //--------------------------------------------------------------------------
  14. //
  15. //  OTimer :: CONSTRUCTOR
  16. //
  17. //--------------------------------------------------------------------------
  18. OTimer::OTimer() : wIDTimer(NULL)
  19. {
  20.     instTimer = MakeObjectThunk((FARPROC) TimerCallback, this);
  21. }
  22.  
  23.  
  24. //--------------------------------------------------------------------------
  25. //
  26. //  OTimer :: DESTRUCTOR
  27. //
  28. //--------------------------------------------------------------------------
  29. OTimer::~OTimer()
  30. {
  31.     stop();     // always stop the timer!
  32.     FreeObjectThunk(instTimer);
  33. }
  34.  
  35.  
  36. //--------------------------------------------------------------------------
  37. //
  38. //  OTimer :: TimerCallback - The actual static callback
  39. //
  40. //--------------------------------------------------------------------------
  41. CALLBACK OTimer::TimerCallback(HWND, UINT, UINT, DWORD dwTime)
  42. {
  43.     // ES:BX set from the thunk 
  44.     OTimer *PThis = (OTimer *) MAKELP(_ES,_BX);  
  45.  
  46.     PThis->timerHit(dwTime);
  47.  
  48.     return 0;
  49. }
  50.  
  51.                  
  52. //--------------------------------------------------------------------------
  53. //
  54. //  OTimer :: go
  55. //
  56. //  starts or re-starts a timer
  57. //  
  58. //--------------------------------------------------------------------------
  59. BOOL OTimer::go(UINT wMsec)
  60. {
  61.     if(wIDTimer) stop();
  62.  
  63.     wIDTimer = SetTimer(NULL, 0, wMsec, (TIMERPROC) instTimer);
  64.  
  65.     return wIDTimer != NULL;
  66. }
  67.  
  68.  
  69. //--------------------------------------------------------------------------
  70. //
  71. //  OTimer :: stop
  72. //
  73. //  stops a timer
  74. //
  75. //--------------------------------------------------------------------------
  76. BOOL OTimer::stop()
  77. {
  78.     if(wIDTimer && KillTimer(NULL, wIDTimer)) {
  79.         wIDTimer = NULL;
  80.         return TRUE;
  81.     }
  82.  
  83.     return FALSE;
  84. }
  85.